package uni.UNIBEE7B8D.view.Study.ZhiboContent;


import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import uni.UNIBEE7B8D.R;


/**
 * A simple {@link Fragment} subclass.
 */
public class WebFragment extends Fragment {


    @BindView(R.id.webView)
    WebView webView;

    String content = "";
    public WebFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_web, container, false);
        ButterKnife.bind(this, view);//注意
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Spanned spanned = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            //使用HTML的方法转义，api24以上方法
            spanned = Html.fromHtml(String.valueOf(content), Html.FROM_HTML_MODE_COMPACT);
        } else {
            //使用HTML的方法转义，api24以下方法
            spanned = Html.fromHtml(String.valueOf(content));
        }
        webView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent ev) {

                ((WebView)v).requestDisallowInterceptTouchEvent(true);

                return false;
            }
        });
        webView.loadData(spanned.toString(), "text/html; charset=UTF-8", null);
       // webView.loadDataWithBaseURL(null,R.string.web_content,"text/html", "utf-8", null);

    }
}
